home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / bsd / sys / disksort.h < prev    next >
Text File  |  1995-02-14  |  3KB  |  120 lines

  1. /* 
  2.  * Copyright (c) 1990 NeXT, Inc.
  3.  *
  4.  * HISTORY
  5.  * 10-Jul-90  Gregg Kellogg (gk) at NeXT
  6.  *    Created
  7.  */ 
  8.  
  9. /*
  10.  * Structures necessary for supporting generic disksorting.
  11.  */
  12. #ifndef    _SYS_DISKSORT_
  13. #define    _SYS_DISKSORT_
  14.  
  15. #import <sys/types.h>
  16. #import <sys/buf.h>
  17. #import <kernserv/queue.h>
  18. #import <kernserv/lock.h>
  19.  
  20. /*
  21.  * Each device must define one of these disksort structures to control
  22.  * the device that it's sorting.  Access to the sorted queue is achieved
  23.  * exclisively through the routines disksort_enter, disksort_first, and
  24.  * disksort_remove.
  25.  */
  26.  
  27. typedef struct ds_bucket ds_bucket_t;
  28.  
  29. struct ds_bucket {
  30.     struct buf    *head;
  31.     struct buf    *tail;
  32.     int        sort_key;        // key bucket's sorted on
  33.     int        pri;
  34.     queue_chain_t    link;
  35. };
  36.  
  37. typedef struct ds_queue ds_queue_t;
  38.  
  39. struct ds_queue {
  40.     queue_chain_t        ds_link;    // links active volume queues.
  41.     void            *ds_data;    // pointer to allocated data.
  42.     u_int            indirect:1,    // use the indirect version?
  43.                 active:2,    // queue active
  44.                         // (driver maintained)
  45.                 busy:1;        // first entry in use
  46.     queue_head_t        activeq;    // active buckets
  47.     int            navail;        // number of alloc'able buckets
  48.     int            last_loc;    // head position
  49.     int            last_pri;    // last priority
  50.     simple_lock_data_t    lock;
  51. };
  52.  
  53. /*
  54.  * Structure defining routines to use for disksorting (loadable support).
  55.  */
  56. typedef struct ds_call ds_call_t;
  57.  
  58. struct ds_call {
  59.         /*
  60.          * Enter a request into the disk queue.
  61.          */
  62.     void (*enter)(ds_queue_t *dsq, struct buf *bp);
  63.         /*
  64.          * Enter a request at the head of the queue.
  65.          */
  66.     void (*enter_head)(ds_queue_t *dsq, struct buf *bp);
  67.         /*
  68.          * Enter a request at the tail of the queue.
  69.          */
  70.     void (*enter_tail)(ds_queue_t *dsq, struct buf *bp);
  71.         /*
  72.          * Return the address of the first buffer in the queue.
  73.          */
  74.     struct buf *(*first)(ds_queue_t *dsq);
  75.         /*
  76.          * Remove a buffer from the queue.  If the first buffer
  77.          * is removed the queue is marked not busy.
  78.          */
  79.     struct buf *(*remove)(ds_queue_t *dsq, struct buf *bp);
  80.         /*
  81.          * Allocate and initialize data needed for this queue.
  82.          */
  83.     void (*alloc)(ds_queue_t *dsq);
  84.         /*
  85.          * Free data from this queue.
  86.          */
  87.     void (*free)(ds_queue_t *dsq);
  88.         /*
  89.          * True if the service is loaded and ready to go.
  90.          * False when shutting down or not loaded.
  91.          */
  92.     u_int available;    // is service available?
  93. };
  94.  
  95. #if    KERNEL
  96. void disksort_enter(ds_queue_t *dsq, struct buf *bp);
  97. void disksort_enter_head(ds_queue_t *dsq, struct buf *bp);
  98. void disksort_enter_tail(ds_queue_t *dsq, struct buf *bp);
  99. struct buf *disksort_first(ds_queue_t *dsq);
  100. struct buf *disksort_remove(ds_queue_t *dsq, struct buf *bp);
  101. void disksort_init(ds_queue_t *dsq);
  102. void disksort_free(ds_queue_t *dsq);
  103.  
  104. /*
  105.  * Inlines
  106.  */
  107. static inline void disksort_qbusy(ds_queue_t *dsq)
  108. {
  109.     dsq->busy = 1;
  110. }
  111. static inline void disksort_qidle(ds_queue_t *dsq)
  112. {
  113.     dsq->busy = 0;
  114. }
  115.  
  116. extern ds_call_t ds_call;
  117. #endif    KERNEL
  118.  
  119. #endif    _SYS_DISKSORT_
  120.